<?php

include ('db_connector.php');

class DAO
{

	static function executeSelect($query, $government = false)
	{
		$dbc = new DBConnector();
		$dbc->connect($government);
		$result = $dbc->select($query);
		$dbc->disconnect();
		
		return $result;		
	}
	
	static function executeQuery($query, $government = false)
	{
		$dbc = new DBConnector();
		$dbc->connect($government);
		$dbc->executeQuery($query);
		$dbc->disconnect();				
	}
	
	
	static function getAllBiddings()
	{
		$query = "SELECT * from biddings;";
		return self::executeSelect($query);
	}
	
	static function addBidding($name, $desc, $begin_date, $end_date) 
	{	    
		$query = "INSERT INTO biddings values(NULL, '$name', '$begin_date', '$end_date', '$desc');";		
		self::executeQuery($query);				
	}
	
	static function getUser($login, $pass) 
	{	    
		$query = "SELECT id, type FROM users where login='$login' and password='$pass';";	
		return self::executeSelect($query);				
	}
	
	static function addUser($name, $surname, $company, $login, $password, $mail)
	{
		$query = "INSERT INTO users values(NULL, '$name', '$surname', '$company', '$login', '$password', '0', '$mail');";		
		self::executeQuery($query);
	}
	
}
?>